package arens
{
	import base.AreaBase;
	
	import controls.GameField;
	
	import events.EnumEvents;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.filesystem.File;
	
	import starling.display.Image;
	import starling.display.Quad;
	import starling.display.Sprite;
	import starling.events.Event;
	import starling.textures.Texture;
	
	import ui.BottomGameMenu;
	import ui.TopGameMenu;
	
	import utils.LoaderResource;
	
	public class PlayArena extends AreaBase
	{
		private var gameField:GameField;
		private var topMenu:TopGameMenu;
		
		public function PlayArena(name:String)
		{
			//TODO: реализация функции
			super(name);
			addEventListener(Event.ADDED_TO_STAGE,addToStage);
		}
		private function addToStage(e:Event):void{
			removeEventListener(Event.ADDED_TO_STAGE,addToStage);
		}
		public override function load():void{
			startLoadingArena();
		}
		
		public override function initial():void{
			trace("start initial");
			
		}
		
		public override function clear():void{
			while(numChildren>0){
				removeChild(getChildAt(0),true);
			}
			super.clear();
			dispose();
		}
		
		
		private function startLoadingArena():void{
			var bg:Quad = new Quad(320,480,0x00FF00);
			addChild(bg);
			gameField = new GameField();
			gameField.addEventListener(GameField.UPDATE_COUNTER,updateTopMenuCounter);
			addChild(gameField);
			
			var bottomMenu:BottomGameMenu = new BottomGameMenu();
			addChild(bottomMenu);
			
			topMenu = new TopGameMenu();
			addChild(topMenu);
			dispatchEvent(new Event(EnumEvents.FINISH_LOAD_ARENA,true));
		}
		private function updateTopMenuCounter(e:Event):void
		{
			topMenu.addStepInCounterTxt();
		}
	}
}